package com.aaa.service;

import com.aaa.dao.UserDaos;
import com.aaa.entity.User;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class UserService{
    @Resource
    UserDaos userDaos;

    public List<User> login(String name, String password) {

        return userDaos.login(name);
    }
    public List<User> select(Integer pageCode, Integer pageSize, User user) {
        Integer a=(pageCode-1)*pageSize;
        return userDaos.select(a, pageSize, user);
    }

    public List<User> selectByNP(String name, String password) {
        return userDaos.selectByNP(name, password);
    }

    public Integer insert(User user) {
        return userDaos.insert(user);
    }

    public Integer updateP(User user) {
        BCryptPasswordEncoder passwordEncoder = new BCryptPasswordEncoder();
        String s = passwordEncoder.encode(user.getPassword());
        user.setPassword(s);
        System.out.println(user);
        return userDaos.updateP(user);
    }

    public Integer update(User user) {
        return userDaos.update(user);
    }

    public Integer updateS(User user) {
        return userDaos.updateS(user);
    }
}
